package com.ziyun.erp.web.modules.quotePrintFactory.controller;

import java.util.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ziyun.erp.common.e.quote.QuotePrintFactoryEnum;
import com.ziyun.erp.common.e.quote.QuotePrintFactoryPriceColourEnum;
import com.ziyun.erp.common.e.quote.QuotoPrintPrintTypeEnum;
import com.ziyun.erp.common.utils.JsonUtils;
import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.quotePrint.entity.QuotePrintEntity;
import com.ziyun.erp.modules.quotePrint.service.QuotePrintService;
import com.ziyun.erp.modules.quotePrintFactory.vo.QuotePrintFactoryEntityVo;
import com.ziyun.erp.modules.quotePrintFactoryPrice.entity.QuotePrintFactoryPriceEntity;
import com.ziyun.erp.modules.quotePrintFactoryPrice.service.QuotePrintFactoryPriceService;
import com.ziyun.erp.web.modules.quotePrint.controller.QuotePrintController;
import io.renren.common.validator.ValidatorUtils;
import net.sf.json.util.JSONUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.quotePrintFactory.entity.QuotePrintFactoryEntity;
import com.ziyun.erp.modules.quotePrintFactory.service.QuotePrintFactoryService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 工厂印刷机配置表
 *
 * @author llc
 * @email 
 * @date 2018-09-07 09:32:19
 */
@RestController
@RequestMapping("quotePrintFactory/quoteprintfactory")
public class QuotePrintFactoryController {
    @Autowired
    private QuotePrintFactoryService quotePrintFactoryService;

    @Autowired
    private QuotePrintService quotePrintService;

    @Autowired
    private QuotePrintFactoryPriceService quotePrintFactoryPriceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("quotePrintFactory:quoteprintfactory:list")
    public R list(@RequestParam Map<String, Object> params){
        //工厂id 此处自营写死
        Long factoryId = 1L;
        params.put("factoryId", factoryId);
        //只获取商务印刷
        params.put("printType","shangwuyinshua");
        Map<String,Object> rsData = this.quotePrintFactoryService.listQuotePrintFactory(params);

        return R.ok().put("page", rsData.get("page")).put("userData",rsData.get("userData"));
    }


    /**
     * 返回工厂以及配价信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("quotePrintFactory:quoteprintfactory:info")
    public R info(@PathVariable("id") Integer id){
        QuotePrintFactoryEntityVo  quotePrintFactoryVo = this.quotePrintFactoryService.getInfo(id);

        return R.ok().put("quotePrintFactoryVo", quotePrintFactoryVo);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("quotePrintFactory:quoteprintfactory:delete")
    public R delete(@RequestBody Integer[] ids){
        //删除quote_print_factory表中数据，修改表中的del_flag字段
        //创建一个Map封装修改的参数
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("update_user",UserUtils.getCurentUser().getUsername());
        this.quotePrintFactoryService.deleteQuotePrintFactory(ids, map);
        return R.ok();
    }

    /**
     * 保存打印机及其价格
     */
    @RequestMapping("/saveWithPrice")
    @RequiresPermissions("quotePrintFactory:quoteprintfactory:save")
    public R savePrintFacotoryWithPrintPrice(@RequestBody QuotePrintFactoryEntityVo quotePrintFactoryVo){
        //工厂id 此处自营写死
        Long factoryId = 1L;
        quotePrintFactoryVo.getQuotePrintFactory().setFactoryId(Integer.valueOf(factoryId.toString()));
        String createName=UserUtils.getCurentUser().getUsername();
        return quotePrintFactoryService.save(quotePrintFactoryVo,createName);
    }

    /**
     * 修改打印机及其价格
     */
    @RequestMapping("/updateWithPrice")
    @RequiresPermissions("quotePrintFactory:quoteprintfactory:update")
    public R update(@RequestBody QuotePrintFactoryEntityVo quotePrintFactoryVo){
        quotePrintFactoryVo.getQuotePrintFactory().setUpdateUser(UserUtils.getCurentUser().getUsername());
        quotePrintFactoryVo.getQuotePrintFactory().setUpdateDate(new Date());
        quotePrintFactoryService.update(quotePrintFactoryVo);//全部更新
        return R.ok();
    }

    /**
     * 修改打印机是否前台展示状态
     */
    @RequestMapping("/updateDisplay/{id}")
    @RequiresPermissions("quotePrintFactory:quoteprintfactory:update")
    public R updateDisplay(@PathVariable("id") Integer id){
        //先根据id查出来，再更改状态
        this.quotePrintFactoryService.updateDisplay(id);

        return R.ok();
    }
}
